home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks95 / NewtANoteSuckANote.sit / Newt-A-Note & Suck-A-Note 1.0 / Newt-A-Note / DropShell.c < prev    next >
Text File  |  1995-06-24  |  7KB  |  311 lines

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Author    Description
  23. **    ---------    ------    ---------------------------------------------
  24. **    23 Jun    94    LDR        Implemented support for disk insertion events
  25. **    02 Feb    94    LDR        Updated for Final SDK & CodeWarrior a2
  26. **                        Removed the ResumeProc as per new Apple recommendations
  27. **    11 Dec 93    SCS        Universal Headers/UPPs (Phoenix 68k/PPC & PPCC)
  28. **                        Skipped System 6 compatible rev of DropShell source
  29. **    09 Dec 91    LDR        Added support for new "Select File…" menu item
  30. **                        Quit now sends AEVT to self to be politically correct
  31. **                        Added support for the new gSplashScreen
  32. **    24 Nov 91    LDR        Added support for the Apple Menu (duh!)
  33. **    29 Oct 91    SCS        Changes for THINK C 5
  34. **    28 Oct 91    LDR        Officially renamed DropShell (from QuickShell)
  35. **                        Added a bunch of comments for clarification
  36. **    06 Oct 91    MTC        Converted to MPW C
  37. **    09 Apr 91    LDR        Added to Projector
  38. **
  39. ******************************************************************************/
  40.  
  41. #ifndef __MWERKS__
  42. #include <Desk.h>
  43. #include <Dialogs.h>
  44. #include <Errors.h>
  45. #include <Files.h>
  46. #include <Fonts.h>
  47. #include <Memory.h>
  48. #include <Menus.h>
  49. #include <StandardFile.h>
  50. #include <TextEdit.h>
  51. #include <Types.h>
  52. #include <Windows.h>
  53. #endif
  54.  
  55. #include "DSGlobals.h"
  56. #include "DSUserProcs.h"
  57. #include "DSAppleEvents.h"
  58.  
  59. #include "DropShell.h"
  60. #include "LlamaTalk.h"
  61. #include "Comms.h"
  62.  
  63.  
  64.  
  65. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent, gCanQuit;
  66. EventRecord    gEvent;
  67. MenuHandle    gAppleMenu, gFileMenu;
  68. DialogPtr    gSplashScreen;
  69.  
  70.  
  71. #ifdef MPW
  72. extern void _DataInit();    
  73. #endif
  74.  
  75.  
  76. #pragma segment Initialize
  77. void InitToolbox (void) 
  78. {
  79.  
  80. #ifdef MPW
  81.     UnloadSeg ((Ptr) _DataInit );
  82. #endif
  83.  
  84.     InitGraf ( &qd.thePort );
  85.     InitFonts ();
  86.     InitWindows ();
  87.     InitMenus ();
  88.     TEInit ();
  89.     InitDialogs (NULL);        // use of ResumeProcs no longer approved by Apple
  90.     InitCursor ();
  91.     FlushEvents ( everyEvent, 0 );
  92.     
  93.     // how about some memory fun! Two should be enough!
  94.     MoreMasters ();
  95.     MoreMasters ();
  96.     }
  97.  
  98. /*
  99.     Let's setup those global variables that the DropShell uses.
  100.     
  101.     If you add any globals for your own use,
  102.     init them in the InitUserGlobals routine in DSUserProcs.c
  103. */
  104. #pragma segment Initialize
  105. Boolean InitGlobals (void) 
  106. {
  107.     long aLong;
  108.  
  109.     gCanQuit        = false;
  110.     gDone            = false;
  111.     gOApped            = false;    // probably not since users are supposed to DROP things!
  112.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  113.     gSplashScreen    = NULL;
  114.  
  115.     return(InitUserGlobals());    // call the user proc
  116. }
  117.  
  118. /*
  119.     Again, nothing fancy.  Just setting up the menus.
  120.     
  121.     If you add any menus to your DropBox - insert them here!
  122. */
  123. #pragma segment Initialize
  124. void SetUpMenus (void) {
  125.  
  126.     gAppleMenu = GetMenu ( kAppleNum );
  127.     AddResMenu ( gAppleMenu, 'DRVR' );
  128.     InsertMenu ( gAppleMenu, 0 );
  129.  
  130.     gFileMenu = GetMenu ( kFileNum );
  131.     InsertMenu ( gFileMenu, 0 );
  132.     DrawMenuBar ();
  133. }
  134.  
  135. /*
  136.     This routine is called during startup to display a splash screen.
  137.     
  138.     This was recommend by the Blue Team HI person, John Sullivan, who
  139.     feels that all apps should display something so that users can easily
  140.     tell what is running, and be able to switch by clicking.  Thanks John!
  141. */
  142. #pragma segment Initialize
  143. void InstallSplashScreen(void) 
  144. {
  145.     #define windowPicID    129
  146.  
  147.     if (!gSplashScreen) {  // show the splash screen window
  148.         gSplashScreen = GetNewDialog(windowPicID, nil, (WindowPtr)(-1));
  149.         DrawDialog(gSplashScreen);
  150.     }
  151. }
  152.  
  153.  
  154. /*    --------------- Standard Event Handling routines ---------------------- */
  155. #pragma segment Main
  156. void ShowAbout () {
  157.     (void) Alert ( 128, NULL );
  158.     }
  159.  
  160.  
  161. #pragma segment Main
  162. void DoMenu ( long retVal ) {
  163.     short    menuID, itemID;
  164.     Str255    itemStr;
  165.  
  166.     menuID = HiWord ( retVal );
  167.     itemID = LoWord ( retVal );
  168.     
  169.     switch ( menuID ) {
  170.         case kAppleNum:
  171.             if ( itemID == 1 )
  172.                 ShowAbout ();    /*    Show the about box */
  173.             else
  174.             {
  175.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  176.                 OpenDeskAcc(itemStr);
  177.             }
  178.             break;
  179.             
  180.         case kFileNum:
  181.             if ( itemID == 1 )
  182.                 SelectFile();        // call file selection userProc
  183.             else {
  184.                 gCanQuit = TRUE;
  185.                 SendQuitToSelf();    // send self a 'quit' event
  186.             }
  187.             break;
  188.         
  189.         default:
  190.             break;
  191.             
  192.         }
  193.     HiliteMenu(0);        // turn it off!
  194.     }
  195.  
  196.  
  197. #pragma segment Main
  198. void DoMouseDown ( EventRecord *curEvent ) {
  199.     WindowPtr    whichWindow;
  200.     short        whichPart;
  201.  
  202.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  203.     switch ( whichPart ) {
  204.         case inMenuBar:
  205.             DoMenu ( MenuSelect ( curEvent->where ));
  206.             break;
  207.         
  208.         case inSysWindow:
  209.             SystemClick ( curEvent, whichWindow );
  210.             break;
  211.         
  212.         case inDrag:
  213.             {
  214.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  215.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  216.             }
  217.         default:
  218.             break;
  219.         }
  220.     }
  221.  
  222.  
  223. #pragma segment Main
  224. void DoKeyDown ( EventRecord *curEvent ) {
  225.     if ( curEvent->modifiers & cmdKey )
  226.         if ( (curEvent->message & 0xFF) == 0x2E)
  227.             gCanQuit = TRUE;
  228.         else
  229.             DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  230.     }
  231.  
  232.  
  233. short isPressed(unsigned short k )
  234. // k =  any keyboard scan code, 0-127
  235. {
  236.     unsigned char km[16];
  237.  
  238.     GetKeys( (void *)km);
  239.     return ( ( km[k>>3] >> (k & 7) ) & 1);
  240. }
  241.  
  242.  
  243. #pragma segment Main
  244. void main ( ) 
  245. {
  246.     InitToolbox ();
  247.     if ( InitGlobals () ) {    // if we succeeding in initting self
  248.         if ( !gHasAppleEvents )
  249.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  250.         else {
  251.             InitAEVTStuff ();
  252.             SetUpMenus ();
  253.             InstallSplashScreen ();
  254.             MOpenComms();
  255.             
  256.             while (! (gDone && gCanQuit) ) {
  257.                 LTIdle(gLlamaTalkGlobals);
  258.                 
  259.                 if (LTIsValidSocket(gLlamaTalkGlobals, gSocket)) {
  260.                     gInDataHdl = LTRead(gLlamaTalkGlobals, gSocket);
  261.                     if (gInDataHdl != nil) {
  262.                         gCanQuit = TRUE;
  263.                         DisposHandle(gInDataHdl);
  264.                     }
  265.                 }
  266.                 else
  267.                     if (LTGetSocketState(gLlamaTalkGlobals, gSocket) == cLTStateError) {
  268.                         DebugStr("\pSocket is in error state, disposing of socket...");
  269.                         LTDisposeSocket(gLlamaTalkGlobals, gSocket);
  270.                         gSocket = 0;
  271.                     }
  272.                 
  273.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  274.                 if ( gWasEvent ) {
  275.                     switch ( gEvent.what ) {
  276.                         case kHighLevelEvent:
  277.                             DoHighLevelEvent ( &gEvent );
  278.                             break;
  279.                             
  280.                         case mouseDown:
  281.                             DoMouseDown ( &gEvent );
  282.                             break;
  283.                             
  284.                         case keyDown:
  285.                         case autoKey:
  286.                             DoKeyDown ( &gEvent );
  287.                             break;
  288.  
  289.                         case diskEvt:
  290.                             if (HiWord(gEvent.message)) {
  291.                                 Point diskInitPt;
  292.                                 
  293.                                 diskInitPt.v = diskInitPt.h = 100;
  294.                                 DILoad();
  295.                                 DIBadMount(diskInitPt, gEvent.message);
  296.                                 DIUnload();
  297.                             }
  298.                             break;
  299.                             
  300.                         default:
  301.                             break;
  302.                     }
  303.                 }
  304.             }
  305.             
  306.             MCloseComms();
  307.         }
  308.         DisposeUserGlobals();    // call the userproc to clean itself up
  309.     }
  310. }
  311.